# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://doc.scrapy.org/en/latest/topics/item-pipeline.html
import csv

class MultiPipeline(object):
    def process_item(self, item, spider):
        return item

class Pipeline_ToCVS(object):

    def __init__(self):
      self.f = open("Movie.csv", "w")
      self.writer = csv.writer(self.f)
      self.writer.writerow(['id', 'name', 'year', 'director', 'screenWriter', 'performer'
                            , 'type', 'nation', 'language', 'releaseDate', 'filmLength'
                            , 'rating', 'ratedCount', 'synopsis'])

    def process_item(self, item, spider):
        Movie_List = [item['Movie_Id'], item['Movie_name'], item['Movie_year'], item['Movie_director'], item['Movie_screenWriter'],
                      item['Movie_performer'], item['Movie_type'], item['Movie_nation'], item['Movie_language'],
                      item['Movie_releaseDate'], item['Movie_Movielength'], item['Movie_rating'],
                      item['Movie_ratedCount'], item['Movie_synopsis']]

        self.writer.writerow(Movie_List)

        return item


class Pipeline_Comment_ToCVS(object):

    def __init__(self):
        self.f = open("Comment.csv", "w")
        self.writer = csv.writer(self.f)
        self.writer.writerow(['comment_id', 'comment_name', 'comment_username', 'comment_content', 'comment_Time'
                                  , ' comment_Votes'])

    def process_item(self, item, spider):
        Movie_List = [item['Movie_comment_movie_id'], item['Movie_comment_movie_name'], item['Movie_comment_userName'],
                      item['Movie_comment_content'], item['Movie_comment_Time'], item['Movie_comment_Votes']]

        self.writer.writerow(Movie_List)

        return item
